package org.rocky.consumer.bean;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author Rocky
 */
@Component
@Aspect
public class MyAspect {
    @Pointcut("execution(* org.rocky.consumer.service.*.*(..))")
    private void pointcut(){
        System.out.println("执行到切面");
    }

    @Around("org.rocky.consumer.bean.MyAspect.pointcut()")
    public Object around(ProceedingJoinPoint pjp){
        long start  = System.currentTimeMillis();
        Object proceed = null;
        try{
            proceed= pjp.proceed();
        }catch(Exception e){
            e.printStackTrace();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        long end = System.currentTimeMillis();
        System.out.println("消耗时间:"+(end-start));
        return proceed;
    }
}
